#ifndef MIFARE_CLASSIC_H
#define MIFARE_CLASSIC_H

#include "nfc/nfc.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "mifare.h"

struct mfc_value_block {
    uint32_t value1;
    uint32_t value2;
    uint32_t value3;
    uint8_t  addr1;
    uint8_t  addr2;
    uint8_t  addr3;
    uint8_t  addr4;
};

#define MFC_C1M 0b00000100
#define MFC_C2M 0b00000010
#define MFC_C3M 0b00000001

struct mfc_trailer_block {
    uint8_t keya[6];
    uint8_t ac[4];
    uint8_t keyb[6];
};

uint8_t mfc_get_permission(uint8_t* pac, uint8_t block);
void mfc_set_permission(uint8_t* pac, uint8_t block, uint8_t bits);
int mfc_authenticate(nfc_device *pnd, nfc_target* pnt, uint8_t sector, mifare_cmd cmd, uint8_t* key);
int mfc_write_data(nfc_device* pnd, nfc_target* pnt, uint8_t sector, uint8_t block, uint8_t* data, uint8_t size);
int mfc_read_data(nfc_device* pnd, nfc_target* pnt, uint8_t sector, uint8_t block, uint8_t* data, uint8_t size);
int mfc_write_value(nfc_device* pnd, nfc_target* pnt, uint8_t sector, uint8_t block, uint32_t value);
int mfc_read_value(nfc_device *pnd, nfc_target *pnt, uint8_t sector, uint8_t block, int *pv);
int mfc_increment(nfc_device *pnd, nfc_target *pnt, uint8_t sector, uint8_t block, uint32_t value);
int mfc_decrement(nfc_device* pnd, nfc_target* pnt, uint8_t sector, uint8_t block, uint32_t value);

#ifdef __cplusplus
}
#endif

#endif // MIFARE_CLASSIC_H
